package com.qf.controller;

import com.qf.pojo.Spit;
import com.qf.service.SpitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 吐槽controller
 * @author 千锋健哥
 */
@RestController
@RequestMapping("/spit")
public class SpitController {

    @Autowired
    private SpitService spitService;

    /**
     * 添加数据
     * @param spit
     */
    @PostMapping("/insert")
    public void insert(@RequestBody Spit spit) {
        spitService.insert(spit);
    }

    /**
     * 修改数据
     * @param spit
     */
    @PutMapping("/update")
    public void update(@RequestBody Spit spit) {
        spitService.update(spit);
    }

    /**
     * 根据id查询一条数据
     * @param id
     * @return
     */
    @GetMapping("/findOne/{id}")
    public Spit findOne(@PathVariable("id") String id) {
        Spit one = spitService.findOne(id);
        return one;
    }

    /**
     * 根据条件查询
     * @param spit
     * @return
     */
    @GetMapping("/find")
    public List<Spit> findSpitByParam(@RequestBody Spit spit) {
        List<Spit> list = spitService.findSpitByParam(spit);
        return list;
    }

    /**
     * 根据id删除
     * @param id
     */
    @DeleteMapping("/delete/{id}")
    public void deleteById(@PathVariable("id") String id){
        spitService.deleteById(id);
    }
}
